﻿namespace Sample
{
    using System;
    using System.IO;
    using log4net;
    using NHibernate.Cfg;
    using NHibernate.Tool.hbm2ddl;

    internal class Program
    {
        private static void Main(string[] args)
        {
            CreateDb();
            DoLogging();

            Console.Write("Press <ENTER> to exit...");
            Console.ReadLine();
        }

        private static void CreateDb()
        {
            var config = new Configuration().Configure();
            SchemaExport export = new SchemaExport(config);
            export.Drop(false, false);
            export.Create(true, true);
        }

        private static void DoLogging()
        {
            ILog logger = CreateLogger();

            logger.Debug("Debug message");
            logger.InfoFormat("Info message");
            logger.Warn("Warn message");
            logger.Error("Error message", new Exception("Test"));
            logger.Fatal("Fatal message", new Exception("Test"));
        }

        private static ILog CreateLogger()
        {
            FileInfo file = new FileInfo("log4net.config");
            log4net.Config.XmlConfigurator.ConfigureAndWatch(file);
            return LogManager.GetLogger(typeof(Program));
        }
    }
}